package com.qf.service;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsBrandMapper;
import com.qf.pojo.DtsBrand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * projectName: wokepase1
 *
 * @author: 强力
 * time: 2021/9/15 16:34
 * description:
 */
@Service
public class BrandServiceImpl implements BrandService{
    @Autowired
    private DtsBrandMapper brandMapper;
    @Override
    public IPage<DtsBrand> findByPage(Integer page, Integer limit, Integer id, String name, String sort, String order) {
        Page<DtsBrand> brandPage=new Page<>();
        QueryWrapper<DtsBrand> queryWrapper=new QueryWrapper<>();
        if (id != null) {
            queryWrapper.eq("id",id);
        }
        if (!StringUtils.isEmpty(name)){
            queryWrapper.like("name",name);
        }
        if (order.equalsIgnoreCase("asc")){
         queryWrapper.orderByAsc();
        }else {
            queryWrapper.orderByDesc();
        }
        IPage<DtsBrand> brandlist = brandMapper.selectPage(brandPage, queryWrapper);
        return brandlist;
    }

}
